﻿#include <iostream>
#include "Temp.h"
#include "ArrayException.h"

int main()
{
    std::cout << "Hello World!\n";

    // 声明装了20个int的数组
    Temp<int, 20> tarray;

    // 按顺序填装，然后逆序打印
    for (int count{ 0 }; count < 20; ++count)
        tarray[count] = count;

    for (int count{ 20 }; count >= 0; --count)
        std::cout << tarray[count] << ' ';
    std::cout << '\n';



    // 声明装了4个double的数组
    Temp<double, 4> doubleArray;

    for (int count{ 0 }; count < 4; ++count)
        doubleArray[count] = 4.4 + 0.1 * count;

    for (int count{ 0 }; count < 4; ++count)
        std::cout << doubleArray[count] << ' ';


    //异常处理
    try
    {
        //处理逻辑
        int sum = 3444 + 234;
        std::cout << "sum=" << sum << "\n";

        //抛出异常
        //throw - 1; 
        throw std::runtime_error("Bad things happened");
    }
    catch (int x) //捕获异常
    {
        std::cout << "exception="<<x << "\n";
    }
    catch (const ArrayException& exception) // 自定义异常
    {
        std::cerr << "An array exception occurred (" << exception.what() << ")\n";
    }
    // 这里会 catch 住 std::exception 和所有的 对应的派生类
    catch (const std::exception& exception)
    {
        std::cerr << "Standard exception: " << exception.what() << '\n';
    }
    catch (...) //捕获所有异常
    {
      
        std::cout << "We caught an exception of an undetermined type\n";
    }
}
